#include <51func.h>
typedef struct student_s {
    int num;
    char name[30];
    float score;
} student_t;
int main(int argc, char *argv[])
{
    // ./2_student file1 
    student_t stuInfo[3] = {
        {1001,"Caixukun",88.8},
        {1003,"Wuyifan",59.9},
        {1005,"Liyifeng",60.0}
    };
    ARGS_CHECK(argc,2);
    int fd = open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    write(fd,stuInfo,sizeof(stuInfo));
   
    lseek(fd,0,SEEK_SET);
    student_t stuRead[3];
    read(fd,stuRead,sizeof(stuRead));//读和写的类型一致
    for(int i = 0; i < 3; ++i){
        printf("%d %s %5.2f\n", stuRead[i].num, stuRead[i].name, stuRead[i].score);
    }
    return 0;
}

